home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / cug191 / sound.doc < prev    next >
Text File  |  1986-03-05  |  43KB  |  1,118 lines

  1. .op
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.                     S O U N D   E F F E C T S
  14.  
  15.                        C Function Library
  16.                           Version 1.0b
  17.  
  18.  
  19.                Copyright (C) 1986 by Paul Canniff
  20.                       All Rights Reserved.
  21.  
  22.  
  23.  
  24.  
  25.                           Paul Canniff
  26.                           P.O. Box 1056
  27.                         Marlton NJ 08053
  28.  
  29.                     CompuServe ID 73047,3715
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.                     
  54.                                                 Updated 05 Mar 86
  55. .paè
  56.  
  57.  
  58.  
  59.                          C O N T E N T S
  60.  
  61.           Introduction  .......................  1
  62.           Installation for Aztec C  ...........  2
  63.           Installation for Ecosoft C  .........  3
  64.           Installation for Lattice C  .........  4
  65.           Installation for other compilers  ...  5
  66.           Using The Library  ..................  6
  67.           Making Music (using PLAY)  ..........  8
  68.           Making Noise (using SOUND)  ......... 10
  69.           Function Summary List  .............. 11
  70.           Individual Function Descriptions  ... 12
  71.           Technical Information  .............. 18
  72.           What To Do When It Doesn't Work  .... 23
  73.           Change Log .......................... 24
  74. .paè.pn 1
  75.  
  76.                           Introduction
  77.  
  78. Thi≤ librar∙ facilitate≤ thσ usσ oµ sounΣ anΣ musiπ oε thσ IBM-P├ ì
  79. famil∙á anΣá compatibles«á  I⌠ ha≤ beeε testeΣ witΦá thσá Latticσ ì
  80. compile≥á versioε 2.1╡ anΣ thσ Man° Azteπ compile≥ versioεá 3.20«  ì
  81. Othe≥ compiler≤ (o≥ version≤ oµ thesσ compilers⌐ shoulΣ worδ jus⌠ ì
  82. fine¼á provideΣá yo⌡ caε rewritσ o≥ modif∙ thσá assembly-languagσ ì
  83. portions«á  ╔á wil∞ bσ glaΣ t∩ hel≡ ge⌠ thσ librar∙ workinτá witΦ ì
  84. other compilers.
  85.  
  86. Thσá maiεá function≤ iε thσá librar∙á arσá play()¼á sound()¼á anΣ ì
  87. sounds()«á  Play(⌐á accept≤á ß forφ oµá musica∞á notation¼á whilσ ì
  88. sounds(⌐á anΣ sounds(⌐ accep⌠ specifiπ frequencie≤ anΣá duration≤ ì
  89. fo≥á greate≥á flexibilit∙á (a⌠ thσ expensσ oµ morσ worδá fo≥á thσ ì
  90. programmer)«  Thesσ function≤ arσ discusseΣ iε morσ detai∞ iε thσ ì
  91. section≤ "Makinτ Musicó anΣ "Makinτ Noise"«  Call≤ t∩ sound(⌐ anΣ ì
  92. play(⌐áá caεá bσá freel∙á intermixeΣá iεá eithe≥á foregrounΣáá o≥ ì
  93. background¼á providinτá ßá flexiblσ high-leve∞ interfacσá t∩á thσ ì
  94. speaker.
  95.  
  96. Al∞á oµá thesσá sound-makinτ routine≤ caε ruεá iεá foregrounΣá o≥ ì
  97. background«  ForegrounΣ mean≤ tha⌠ thσ sounΣ i≤ generateΣ iε mucΦ ì
  98. thσá samσá wa∙á tha⌠ mos⌠ othe≥á P├á outpu⌠á i≤á generated╗á  thσ ì
  99. applicatioεá request≤ tha⌠ i⌠ bσ done¼á thσ drive≥ doe≤á it¼á anΣ ì
  100. theε i⌠ return≤ t∩ thσ application«á  Thi≤ i≤ straightforwarΣ anΣ ì
  101. clean.
  102.  
  103. BackgrounΣ i≤ thσ fanc∙ way«á  Thσ musiπ o≥ thσ sounΣ effect≤ arσ ì
  104. requesteΣá b∙á thσ application¼á whicΦ caε theε continuσá t∩á ruε ì
  105. whilσ thσ drive≥ control≤ thσ speaker«á  Thi≤ allow≤ yo⌡ t∩á pla∙ ì
  106. somσá musiπá whilσ you≥ prograφ perform≤ somσá operations¼á whicΦ ì
  107. might be better than just flashing WAIT at the user.
  108.  
  109. Iε addition¼á thσ librar∙ include≤ ß numbe≥ oµ low-leve∞ routine≤ ì
  110. tha⌠ acces≤ thσ speake≥ directly«  
  111.  
  112. .paè.he SounΣ Effect≤                                Genera∞ Installation
  113.  
  114. Thσá followinτá genera∞á installatioε procedurσá applie≤á t∩á al∞ ì
  115. supporteΣ compilers«  
  116.  
  117. (1)  First¼ se⌠ u≡ you≥ "worδ area"¼ whethe≥ i⌠ bσ ß subdirector∙ ì
  118. áááááoεá ß harΣ disk¼á o≥ ß flopp∙ disk«á  Iµ yo⌡ havσ rooφ oεá ß ì
  119. ááááácurren⌠ worδ disk¼á o≥ iε you≥ usua∞ ├ subdirectory¼ yo⌡ ma∙ ì
  120. áááááwan⌠á t∩ usσ them«á  Whereve≥ yo⌡ decidσ upon¼á thi≤ disδ o≥ ì
  121. ááááádiectory will be referred to as your "work area".
  122.  
  123. (2)á Cop∙ al∞ .├ anΣ .╚ file≤ froφ thσ distributioε disδ t∩á you≥ ì
  124. áááááworδá area«á  
  125.  
  126. (3)  Therσ arσ als∩ somσ assembly-langaugσ sourcσ file≤ whicΦ yo⌡ ì
  127. áááááwil∞ need¼ calleΣ DELA┘ anΣ SOUNDINT«  Therσ arσ version≤ oµ ì
  128. áááááthesσ file≤ oε thσ disδ fo≥ eacΦ supporteΣá compiler«á  Cop∙ ì
  129. áááááthσá prope≥ file≤ t∩ you≥ worδ area¼á changinτ thσ extensioε ì
  130. ááááát∩ .AS═ iε thσ process.
  131.  
  132. ááááá       AZTEC:    *.ASZ  ->  *.ASM
  133. ááááá       LATTICE:  *.ASL  ->  *.ASM
  134. ááááá       ECOSOFT:  *.ASE  ->  *.ASM
  135.     
  136. (*)  Kee≡á thσ origina∞ distributioε disδ iε ß safσá place╗á  al∞ ì
  137. áááááfurthe≥ action≤ discusseΣ shoulΣ bσ donσ oε you≥ worδá area¼ ì
  138. áááááno⌠ thσ distributioε disk.
  139.  
  140. (2)  Edi⌠á thσ filσ SOUND.╚ anΣ makσ surσ tha⌠ thσ onl∙á compile≥ ì
  141. áááááflaτ se⌠ i≤ thσ onσ fo≥ you≥ compiler«á  Tha⌠ flaτ shoulΣ bσ ì
  142. áááááset to 1, all others to 0.
  143.  
  144. (3)ááCompilσá thσ ├ files«á  The∙ includσ thσ followinτ ╚á files¼ ì
  145. áááááwhich should be included with your compiler:
  146.  
  147. ááááá     Lattice, Ecosoft:     STDIO.H, DOS.H
  148. ááááá     Aztec:                STDIO.H, MODEL.H
  149.  
  150. (4)  Assemblσá thσá .AS═ file≤ usinτ thσ assemble≥ provideΣá witΦ ì
  151. áááááyou≥áá compiler¼áá thσá Miscrosof⌠áá Macr∩áá Assembler¼áá o≥ ì
  152. áááááequivalent«á  Thσá followinτ "macroó header≤ arσ includeΣ b∙ ì
  153. áááááthe assembly files:
  154.  
  155. ááááá     Lattice:       DOS.MAC
  156. ááááá     (all others)   -none-     
  157.  
  158. (5)ááThσá filσá SOUNDTS╘á i≤á no⌠ ß par⌠á oµá thσá SounΣá Effect≤ ì
  159. ááááálibrary¼á bu⌠á i≤ furnisheΣ a≤ aε examplσ oµ aεá applicatioε ì
  160. ááááácallinτá thσ sounΣ functions«á  T∩ tes⌠á thσá library¼á linδ ì
  161. áááááSOUNDTS╘á t∩á al∞á thσ sounΣ functions¼á anΣá an∙á necessar∙ ì
  162. ááááámodules.  The following modules are required:
  163.  
  164. ááááá     Lattice:       C.OBJ, LC.LIB
  165. ááááá     Ecosoft:       ??
  166. ááááá     Aztec:         C.LIB
  167. .paè.he SounΣ Effect≤                         Installatioε - Man° » Aztec
  168.  
  169.              Manx Aztec C Version 3.20 Installation
  170.  
  171. Note:á Olde≥ Man° compiler≤ (sucΦ a≤ versioε 1.06⌐ shoulΣ requirσ ì
  172. ááááááán∩ changσ t∩ thσ followinτ procedure.
  173.  
  174. Beforσá starting¼á se⌠á u≡á you≥ "worδ area"¼á whethe≥á i⌠á bσá ß ì
  175. subdirectory on a hard disk, or a floppy disk.   Then ...
  176.  
  177. (1)á Cop∙á thσ .├ anΣ .╚ file≤ t∩ you≥ worδ diskettσ o≥ harΣ disδ ì
  178. ááááásubdirectory«á  Cop∙á al∞ .AS╠ file≤ t∩ .AS═ file≤á oεá you≥ ì
  179. áááááworδá area«á  Kee≡ thσ origina∞ distributioε disδ iε ßá safσ ì
  180. áááááplace╗  al∞ furthe≥ action≤ discusseΣ shoulΣ bσ donσ oε you≥ ì
  181. áááááworδ area¼ no⌠ thσ distributioε disk.
  182.  
  183. (2)  Edi⌠á thσ filσ SOUND.╚ anΣ makσ surσ tha⌠ thσ onl∙á compile≥ ì
  184. áááááflag set to 1 is C_AZTEC. 
  185.  
  186. (3)ááCompilσá thσ ├ files«á  The∙ includσ thσ followinτ ╚á files¼ ì
  187. áááááwhich should be included with your compiler:
  188.  
  189. ááááá     STDIO.H     MODEL.H
  190.  
  191. (4)  Assemblσá thσá .AS═á file≤ usinτ thσ Man°á Azteπá Assembler¼ ì
  192. áááááMiscrosof⌠ Macr∩ Assemble≥ o≥ equivalent.
  193.  
  194. (5)ááLinδá thσ filσ SOUNDTEST.OB╩ t∩ thσ res⌠ oµ .OBJ'≤á produceΣ ì
  195. áááááb∙ thσ abovσ commands¼ anΣ t∩ thσ ├ librar∙ (C.LIB)« 
  196.  
  197. (6)ááIµá yo⌡ hea≥ music¼á yo⌡ havσ correctl∙ installeΣ you≥ sounΣ ì
  198. ááááároutines«á  Yo⌡á ma∙ usσ LI┬ o≥ PLIB8╢ t∩ forφ theφá int∩á ß ì
  199. ááááálibrar∙ iµ yo⌡ want«á  Notσ tha⌠ yo⌡ wil∞ havσ t∩ repea⌠ thσ ì
  200. áááááinstallatioε procedurσ fo≥ ever∙ memor∙ mode∞ yo⌡ use«á  Oh¼ ì
  201. áááááyes¼á yo⌡á caε deletσ thσ SOUNDTS╘ file≤ wheε yo⌡ arσá done¼ ì
  202. áááááthougΦ thσ sourcσ give≤ ß gooΣ examplσ oµ thσ correc⌠ wa∙ t∩ ì
  203. áááááacces≤ thσ library.
  204.  
  205.                            Aztec Notes
  206.  
  207. (1)  Sound_done(⌐ mus⌠ als∩ bσ calleΣ beforσ exitinτ aεá overlay¼ ì
  208. áááááiµ thσ overla∙ contain≤ thσ SounΣ Effect≤ codσ anΣ data«  Iµ ì
  209. ááááábotΦá codσ anΣ datß oµ thσ SounΣ Effect≤ function≤ residσ iε ì
  210. áááááthe root, this is not necessary.
  211.  
  212. .paè.he SounΣ Effect≤                              Installatioε - Ecosoft
  213.  
  214.                Ecosoft C Version 3.02 Installation
  215.  
  216. Beforσá starting¼á se⌠á u≡á you≥ "worδ area"¼á whethe≥á i⌠á bσá ß ì
  217. subdirectory on a hard disk, or a floppy disk.   Then ...
  218.  
  219. (1)á Cop∙á thσ .├ anΣ .╚ file≤ t∩ you≥ worδ diskettσ o≥ harΣ disδ ì
  220. ááááásubdirectory«á  Cop∙á al∞ .ASE file≤ t∩ .AS═ file≤á oεá you≥ ì
  221. áááááworδá area«á  Kee≡ thσ origina∞ distributioε disδ iε ßá safσ ì
  222. áááááplace╗  all furthe≥ action≤ discusseΣ shoulΣ bσ donσ oε you≥ ì
  223. áááááworδ area¼ no⌠ thσ distributioε disk.
  224.  
  225. (2)  Edi⌠á thσ filσ SOUND.╚ anΣ makσ surσ tha⌠ thσ onl∙á compile≥ ì
  226. áááááflag set to 1 is C_ECOSOFT.
  227.  
  228. (3)ááCompilσá thσ ├ files«á  The∙ includσ thσ followinτ ╚á files¼ ì
  229. áááááwhich should be included with your Lattice Compiler:
  230.  
  231. ááááá     STDIO.H     DOS.H
  232.  
  233. (4)ááAssemblσá thσ .AS═ file≤ usinτ thσ Microsof⌠ Macr∩ Assemble≥ ì
  234. áááááo≥ equivalent«á  Thσ filσ PRO.╚ mus⌠ bσ present«á  Thi≤ filσ ì
  235. ááááái≤ includeΣ iε thσ Ecosoft ├ packagσ anΣ allow≤ thσ assembl∙ ì
  236. ááááámodule≤ t∩ kno≈ thσ memor∙ mode∞ iε use.
  237.  
  238. (5)ááLinδá thσ filσ SOUNDTEST.OB╩ t∩ thσ res⌠ oµ .OBJ'≤á produceΣ ì
  239. áááááb∙á thσá abovσá commands¼á anΣá t∩á thσá Ecosof⌠á ├á librar∙ ì
  240. ááááá(ECOC.LIB)« 
  241.  
  242. (6)ááIµá yo⌡ hea≥ music¼á yo⌡ havσ correctl∙ installeΣ you≥ sounΣ ì
  243. ááááároutines«á  Yo⌡á ma∙ usσ LI┬ o≥ PLIB8╢ t∩ forφ theφá int∩á ß ì
  244. ááááálibrar∙ iµ yo⌡ want«á  Notσ tha⌠ yo⌡ wil∞ havσ t∩ repea⌠ thσ ì
  245. áááááinstallatioε procedurσ fo≥ ever∙ memor∙ mode∞ yo⌡ use«á  Oh¼ ì
  246. áááááyes¼á yo⌡á caε deletσ thσ SOUNDTS╘ file≤ wheε yo⌡ arσá done¼ ì
  247. áááááthougΦ thσ sourcσ give≤ ß gooΣ examplσ oµ thσ correc⌠ wa∙ t∩ ì
  248. áááááacces≤ thσ library.
  249.  
  250.                           Ecosoft Notes
  251.  
  252. (1)ááThσá filσ SOUNDP.╚ i≤ provideΣ t∩ definσ thσá SounΣá Effect≤ ì
  253. ááááácallablσá functions¼á usinτ thσ prototypσ form«á  Iµ yo⌡ arσ ì
  254. áááááusinτá prototyping¼á thi≤á filσ shoulΣ bσá includeΣá iεá an∙ ì
  255. ááááásource module that calls the Sound Effects library.
  256.  
  257. .paè.he SounΣ Effect≤                              Installatioε - Lattice
  258.  
  259.            Lattice C Version 2.14 or 2.15 Installation
  260.  
  261. Note║á Thσ ne≈ Latticσ compiler≤ (versioε 3.xx⌐ shoulΣ requirσ n∩ ì
  262.        changσ t∩ thσ followinτ procedure.
  263.  
  264. Beforσá starting¼á se⌠á u≡á you≥ "worδ area"¼á whethe≥á i⌠á bσá ß ì
  265. subdirectory on a hard disk, or a floppy disk.   Then ...
  266.  
  267. (1)á Cop∙á thσ .├ anΣ .╚ file≤ t∩ you≥ worδ diskettσ o≥ harΣ disδ ì
  268. ááááásubdirectory«á  Cop∙á al∞ .AS╠ file≤ t∩ .AS═ file≤á oεá you≥ ì
  269. áááááworδá area«á  Kee≡ thσ origina∞ distributioε disδ iε ßá safσ ì
  270. áááááplace╗  all furthe≥ action≤ discusseΣ shoulΣ bσ donσ oε you≥ ì
  271. áááááworδ area¼ no⌠ thσ distributioε disk.
  272.  
  273. (2)  Edi⌠á thσ filσ SOUND.╚ anΣ makσ surσ tha⌠ thσ onl∙á compile≥ ì
  274. áááááflag set to 1 is C_LATTICE.
  275.  
  276. (3)ááCompilσá thσ ├ files«á  The∙ includσ thσ followinτ ╚á files¼ ì
  277. áááááwhich should be included with your Lattice Compiler:
  278.  
  279. ááááá     STDIO.H     DOS.H
  280.  
  281. (4)ááAssemblσ thσ .AS═ file≤ usinτ thσ Microsof⌠ Macr∩á Assemble≥ ì
  282. áááááo≥ equivalent«  Thσ filσ DOS.MA├ mus⌠ bσ present«  Thi≤ filσ ì
  283. ááááái≤ includeΣ iε thσ Latticσ ├ packagσ anΣ allow≤ thσ assembl∙ ì
  284. ááááámodulσs t∩ kno≈ thσ memor∙ mode∞ iε use.
  285.  
  286. (5)ááLinδá thσ filσ SOUNDTEST.OB╩ t∩ thσ res⌠ oµ .OBJ'≤á produceΣ ì
  287. áááááb∙á thσá abovσá commands¼á anΣá t∩á thσá Latticσá ├á librar∙ ì
  288. ááááá(LC.LIB). 
  289.  
  290. (6)ááIµá yo⌡ hea≥ music¼á yo⌡ havσ correctl∙ installeΣ you≥ sounΣ ì
  291. ááááároutines«á  Yo⌡á ma∙ usσ LI┬ o≥ PLIB8╢ t∩ forφ theφá int∩á ß ì
  292. ááááálibrar∙ iµ yo⌡ want«á  Notσ tha⌠ yo⌡ wil∞ havσ t∩ repea⌠ thσ ì
  293. áááááinstallatioε procedurσ fo≥ ever∙ memor∙ mode∞ yo⌡ use«á  Oh¼ ì
  294. áááááyes¼á yo⌡á caε deletσ thσ SOUNDTS╘ file≤ wheε yo⌡ arσá done¼ ì
  295. áááááthougΦ thσ sourcσ give≤ ß gooΣ examplσ oµ thσ correc⌠ wa∙ t∩ ì
  296. áááááacces≤ thσ library.
  297.  
  298.                           Lattice Notes
  299.  
  300. (1)  Wheε compilinτ thσ SounΣ Effect≤ functions¼á bσ usurσ t∩ usσ ì
  301. áááááthσá correc⌠á compile≥ flag≤ anΣ DOS.MA├ file¼á s∩ tha⌠á thσ ì
  302. áááááSounΣá Effect≤ function≤ arσ usinτ thσ samσ memor∙ mode∞á a≤ ì
  303. áááááyou≥ application«á  Yo⌡ ma∙ wan⌠ t∩ compilσ fou≥ version≤ oµ ì
  304. áááááthe Sound Effects functions, one for each memory model.
  305.  
  306. (2)ááBσá surσá t∩ compilσ SounΣ Effect≤ function≤ usinτ thσá "-vó ì
  307. ááááácompile≥ flaτ t∩ disablσ stacδ checking«  Thi≤ i≤ compatiblσ ì
  308. áááááwitΦá thσá Latticσ library«á  No⌠ disablinτá stacδá checkinτ ì
  309. ááááácoulΣ resul⌠ iε detectioε oµ ß bogu≤ "stacδ overflowó durinτ ì
  310. áááááthσáá time≥á interrup⌠á handler'≤á execution«áá  Thi≤áá wil∞ ì
  311. áááááterminate the application.
  312. .paè.he SounΣ Effect≤                               Installatioε - Others
  313.  
  314.  
  315.                      Non-Supported Compilers
  316.  
  317. T∩á usσá thσá SounΣ Effect≤ librar∙ witΦ ßá compile≥á othe≥á thaε ì
  318. Latticσá o≥á Aztec¼á yo⌡á wil∞á havσ t∩á bσá familia≥á witΦá you≥ ì
  319. compile≥á iε orde≥ t∩ customizσ thσ fe≈ assemble≥ routines«á  Thσ ì
  320. followinτá question≤ shoulΣ bσ answereΣ first«á  Thσ answer≤á fo≥ ì
  321. thσ supporteΣ compiler≤ arσ giveε fo≥ reference.
  322.  
  323.  
  324.                                             Lattice  Manx  Yours?
  325.                                             -------  ----  ------
  326.  o Doe≤á you≥ compile≥ appenΣ o≥á prepenΣ ì
  327. áááaεá underscorσá t∩á thσ namσá oµá eacΦ ì
  328. áááfunction?                                   N      Y
  329.  
  330.  o Where does the compiler put parameters?   Stack   Stack
  331.  
  332. áo Wherσá doe≤á you≥ compile≥á placσá it≤ ì
  333. áááreturn values for int?                     AX      AX
  334. áááFor long int?                             AX,BX   DX,AX
  335.  
  336. áo Doe≤ you≥ compile≥ usσ nea≥ calls¼ fa≥ ì
  337. ááácalls, or allows both?                    Both    Both
  338.  
  339.  o What provision does your library make     inp()  inport()
  340.    for access to the I/O ports?             outp()  outport()
  341.  
  342.  
  343. .paè.he Sound Effects                                 General Information
  344.  
  345.                         Using The Library
  346.  
  347. Usinτ thσ SounΣ Effect≤ librar∙ i≤ simila≥ t∩ usinτ thσá standarΣ ì
  348. library'≤á I/╧ functions«á  Therσ i≤ aε "open"¼á somσ operations¼ ì
  349. thσá ßá "close"«á  Iε thσ case¼á thσ openinτ functioεá i≤á calleΣ ì
  350. sound_init(⌐ anΣ thσ closinτ functioε i≤ sound_done()«  Onσ poin⌠ ì
  351. tha⌠á canno⌠á bσ stresseΣ overmucΦ i≤ thσ importancσá oµá callinτ ì
  352. sound_done(⌐á beforσ exitinτ thσ program«á  An∙ applicatioε whicΦ ì
  353. use≤á thσ sounΣ librar∙ shoulΣ cal∞ sound_done(⌐ a⌠ al∞á possiblσ ì
  354. exi⌠ points.
  355.  
  356. Note the following things about sound_done():
  357.  
  358.      (1)á I⌠á neve≥á hurt≤ t∩ cal∞á it«á  Sound_done(⌐á know≤á iµ ì
  359. áááááááááásound_init(⌐ ha≤ beeε called¼ anΣ act≤ accordingly.
  360.  
  361. ááááá(2)ááWheε calleΣ i⌠ wil∞ kil∞ an∙ musiπ stil∞ playing.
  362.  
  363. Thσ oppositσ numbe≥ oµ sound_done(⌐ i≤ sound_init()¼á wh∩á shoulΣ ì
  364. (oµá course⌐ bσ calleΣ first¼á beforσ an∙ othe≥ sounΣá functions«  ì
  365. I⌠á i≤ possiblσ t∩ ge⌠ awa∙ withou⌠ callinτ sound_init()¼á iµ yo⌡ ì
  366. wan⌠ t∩ pla∙ iε modσ 1«á  Bu⌠ i⌠ reall∙ i≤ mucΦ neate≥ t∩ cal∞ i⌠ ì
  367. anyway.
  368.  
  369. Wha⌠ i≤ modσ 1┐á  GlaΣ yo⌡ asked«á  Iε thσ play(⌐ function¼ therσ ì
  370. i≤ ß MOD┼ sub-commanΣ whicΦ ha≤ t∩ d∩ witΦ ho≈ note≤ arσá played«  ì
  371. Bu⌠á outsidσá oµ tha⌠ littlσ corner¼á wheε wσ sa∙ "modeóá wσá arσ ì
  372. talkinτ abou⌠ theε WHE╬ anΣ HO╫ oµ thσ sounΣ output.
  373.  
  374. Yo⌡á go⌠á ßá tastσ oµ thσ meaninτ oµ mode≤ iε thσá discussioεá oµ ì
  375. BackgrounΣá anΣá ForegrounΣá iεá thσáá introduction.áá  Real-timσ ì
  376. programmers¼á forge⌠ you≥ usua∞ understandinτ oµ thesσ terms«  Iε ì
  377. term≤á oµ thi≤ librar∙ musiπ playinτ iε ForegrounΣ play≤ wheε yo⌡ ì
  378. tel∞á i⌠ to¼á anΣ you≥ applicatioε caε d∩ nothinτ elsσ unti∞á thσ ì
  379. musiπ i≤ finished«á  Musiπ iε BackgrounΣ i≤ jus⌠ "se⌠ upó b∙ you≥ ì
  380. commanΣ t∩ play¼á anΣ actuall∙ play≤ whilσ you≥ applicatioε runs«  ì
  381. So¼á i⌠á i≤á "backgrounΣ musicó fo≥ thσá application¼á hencσá thσ ì
  382. terminology«  
  383.  
  384. Notσáá tha⌠áá thσáá term≤á musiπá anΣá sounΣá arσáá useΣáá rathe≥ ì
  385. interchangeably«áá  Musiπá usinτá norma∞á note≤á i≤á mos⌠á easil∙ ì
  386. generateΣá b∙á thσ play(⌐ function¼á whilσ sound(⌐ give≤á ßá morσ ì
  387. flexiblσá interfacσ iµ yo⌡ arσ int∩á strangσá frequencies«á  BotΦ ì
  388. function≤ caε operatσ iε ForegrounΣ anΣ Background.
  389.  
  390. .cp 12èTherσá arσá actuall∙ fivσ mode≤ iε whicΦ thσ sounΣá routine≤á caε ì
  391. run«  Seσ thσ "Technica∞ Informationó sectioε fo≥ ß morσ completσ ì
  392. descriptioε oµ thσ timinτ techniques«  Thσ defaul⌠ modσ i≤ 1.
  393.  
  394.   Mode      When          Timing Method
  395.   ----   ----------    -------------------------
  396.     1    Foreground    Delay Loop
  397.     2    Foreground    Standard Clock Interrupt
  398.     3    Foreground    Enhanced Clock Interrupt  (*)
  399.     4    Background    Standard Clock Interrupt
  400.     5    Background    Enhanced Clock Interrupt  (*)
  401.  
  402.  
  403. Thσá modσ numbe≥ showε abovσ i≤ thσ valuσ yo⌡ shoulΣ givσ t∩á thσ ì
  404. firs⌠ paramete≥ t∩ sound_init()«  Thσ seconΣ paramete≥ i≤ sueΣ a≤ ì
  405. ßá true/falsσ flag¼á anΣ tell≤ sound_init(⌐ whethe≥ t∩ instal∞á ß ì
  406. breaδ handler«á  Thσ breaδ handle≥ act≤ a≤ ß safet∙ feature╗á  i⌠ ì
  407. make≤ surσ tha⌠ sound_done(⌐ i≤ calleΣ beforσ thσ applicatioεá i≤ ì
  408. terminated by the user typing Control-C or Control-Break.
  409.  
  410. Iµá yo⌡ providσ you≥ owε breaδ handler¼á yo⌡ wil∞ wan⌠ t∩ disablσ ì
  411. thσá built-iεá handler«á  Jus⌠ makσ surσ tha⌠ yo⌡á includeΣá tha⌠ ì
  412. handle≥á iεá thσá lis⌠á oµá possiblσá exits¼á s∩á tha⌠á i⌠á call≤ ì
  413. sound_done() before terminating the application.  
  414.  
  415. Iµá yo⌡ don'⌠ havσ ß breaδ handle≥ buil⌠ iε t∩á thσá application¼ ì
  416. let sound_init() put one in for you.
  417.  
  418. OK¼á no≈á  yo⌡á kno≈ tha⌠ you≥ applicatioε shoulΣ looδá somethinτ ì
  419. like this:
  420.  
  421.      main()
  422.      {
  423.           sound_init(m,1);
  424.           .
  425.           .     
  426.           .
  427.           sound_done();
  428.      }
  429.  
  430. That'≤á prett∙á boring«á  Yo⌡ caε spicσ i⌠ u≡ afte≥á readinτá thσ ì
  431. section≤á "Makinτá Musicó anΣ "Makinτ Noise"«á  Onσá morσá usefu∞ ì
  432. functioε beforσ yo⌡ g∩ ..«á quiet()«á  Iµ yo⌡ se⌠ u≡ ß lonτ piecσ ì
  433. oµá backgrounΣ music¼á anΣ fo≥ somσ reasoε havσ t∩ kil∞ i⌠á earl∙ ì
  434. (bu⌠ no⌠ ge⌠ read∙ t∩ exit)¼á cal∞ quiet()«á  I⌠ ha≤ n∩ effec⌠ iε ì
  435. ForegrounΣ modes.
  436.  
  437.  
  438.                            ----------
  439.  
  440.      (*)  The enhanced modes currently produce the same
  441.           results as the standard modes.  In a future 
  442.           version these modes will provide better time
  443.           resolution.  See "Tech Tips" for details.
  444. .paè.he Sound Effects                                        Making Music
  445.  
  446.                           Making Music 
  447.                           (Using Play)
  448.  
  449. Thσá pla∙ functioε translate≤ ß musica∞ scorσ int∩á sounds«á  Thσ ì
  450. scorσ i≤ writteε usinτ ß specia∞ notatioε describeΣ below«á  Thi≤ ì
  451. notatioεá allow≤á thσá usσ oµ ╕ octave≤ oµ 1▓á note≤á each¼á witΦ ì
  452. various tempos, etc.  The format of pla() is:
  453.  
  454.      void play(m)
  455.      char *m;
  456.  
  457. Command≤ arσ ß singlσ lette≥ followeΣ immediatel∙ b∙ onσ o≥á morσ ì
  458. arguments¼á iµá necessary«á  Spaces¼á commas¼á anΣ semicolon≤ ma∙ ì
  459. appea≥ betweeε command≤ fo≥ clarity¼ bu⌠ arσ ignoreΣ b∙ play().
  460.  
  461.  
  462. Aáto G:   Thesσ arσ thσ note≤ ┴ througΦ G¼ iε thσ curren⌠ octave«  ì
  463. áááááááááá┴á notσá ma∙ bσ followeΣ b∙ u≡ t∩ threσá modifiers¼á iε ì
  464. ááááááááááthi≤ orde≥ only:
  465.  
  466. áááááááááá     Sharp/Fla⌠ indication║  ú o≥ ½ i≤ sharp;
  467. áááááááááá                             - i≤ flat.
  468. áááááááááá     Notσ length║  numbe≥ froφ ▒ t∩ 6┤ (seσ L)
  469. áááááááááá     Dots║ U≡ t∩ 10 dots.  A dotted note plays for 3/2
  470.                      of it's normal time.  Two dots = 9/4, three
  471.                      dots = 27/8, etc.
  472.  
  473. ááááááááááExamplσs (assuminτ thσ curren⌠ notσ lengtΦ i≤ 4):
  474.  
  475. áááááááááá     C+        C sharp 1/4 note
  476. áááááááááá     C+8       C sharp 1/8 note
  477. áááááááááá     B-«       ├ shar≡ 1/┤ notσ dotteΣ ╜ 3/╕ note
  478. áááááááááá     A2.       A 1/2 note dotted = 3/4 note
  479.  
  480.  
  481. LnááááááááSet≤ thσ curren⌠ notσ length«  Notσ lengtΦ i≤ 1/n¼ s∩ ß ì
  482. ááááááááááparamete≥á oµ ┤ wil∞ se⌠ subsequen⌠ notσ t∩ 1/┤á notes«  ì
  483. ááááááááááIndividua∞á note≤ ma∙ overridσ thσ curren⌠ lengtΦá witΦ ì
  484. ááááááááááaε explici⌠ lengtΦ (seσ abovσ examples)«á  Thσ rangσ i≤ ì
  485. áááááááááá▒ t∩ 64.
  486.  
  487. ááááááááááNotσá lengtΦá combine≤á witΦá temp∩á t∩á determinσá thσ ì
  488. ááááááááááduratioε oµ thσ note«  LengtΦ i≤ measureΣ a≤ ß fractioε ì
  489. ááááááááááoµá ß wholσ note¼á whilσ temp∩ i≤ iε quarter-note≤á pe≥ ì
  490. áááááááááásecond«á  Fo≥á example¼á witΦ ß temp∩ oµ 3▓ anΣ ßá notσ ì
  491. áááááááááálengtΦ oµ 2¼ ß notσ wil∞ las⌠ fo≥ 1/1╢ oµ ß second.
  492.  
  493. .cp 10èMxááááááááSets the mode of the music.  There are three modes:
  494.  
  495. áááááááááá   x=Ná(NORMAL)║á  note≤ arσ playeΣ fo≥ 7/╕ oµ thσ notσ ì
  496. ááááááááááááááááátime¼ witΦ thσ remaininτ 1/╕ beinτ ß rest.
  497.  
  498. áááááááááááááx=Sá(STACCATO)║ note≤ arσ playeΣ fo≥ 3/┤ oµ thσ notσ ì
  499. ááááááááááááááááátime¼ witΦ thσ remaininτ 1/┤ beinτ ß rest.
  500.  
  501. áááááááááááááx=L (LEGATO)║á note≤á arσ playeΣ fo≥ thσá ful∞á notσ ì
  502. ááááááááááááááááátime¼ witΦ n∩ rest.
  503.  
  504.           Thσ mode≤ ForegrounΣ anΣ BackgrounΣ havσ nothinτ t∩á d∩ ì
  505. ááááááááááwitΦ thesσ mode≤ !
  506.  
  507. Nná       Play≤ notσ ε (rangσ 0..84)¼á wherσ ░ mean≤ silence«  Iµ ì
  508. ááááááááááthσá argumen⌠ i≤ missinτ o≥ ou⌠ oµ range¼á n∩á notσá i≤ ì
  509. ááááááááááplayed.  Cannot be dotted or given explicit length.
  510.  
  511. OnááááááááSet≤ octavσ t∩ ε (rangσ 0..7)«á  Iµ argumen⌠ i≤ ou⌠á oµ ì
  512. áááááááááárange, current octave remains unchanged.
  513.  
  514. P[n][.]áááPausσ o≥ rest╗á  seσ thσ rule≤ fo≥ notσ lengtΦ (n⌐á anΣ ì
  515. áááááááááádottinτá fo≥á thσá regula≥ note≤á A-╟á above«á  Iµá thσ ì
  516. ááááááááááargument is missing or invalid, no pause takes place.
  517.  
  518. RáááááááááResets to default values.  Resets the following:
  519. áááááááááá          Octave = 4
  520. áááááááááá          Length = 1
  521. áááááááááá          Mode = Normal
  522. áááááááááá          Tempo = 120
  523.  
  524. TnááááááááTempo¼á whicΦá ma∙ rangσ froφ 3▓ t∩ 255¼á control≤á thσ ì
  525. áááááááááánumbe≥á oµ quarter-note≤ pe≥ second«á  Thσá defaul⌠á i≤ ì
  526. áááááááááá120.
  527.  
  528. <áááááááááMove≤ dowε onσ octave«á  Iµ alread∙ a⌠ octavσ 0¼á stay≤ ì
  529. ááááááááááthere.
  530.  
  531. >áááááááááMove≤á u≡ onσ octave«á  Iµ alread∙ a⌠ octavσá 7¼á stay≤ ì
  532. ááááááááááthere.
  533.  
  534.  
  535. .paè.he Sound Effects                                        Making Noise
  536.  
  537.                           Making Noise 
  538.                     (Using Sound and Sounds)
  539.  
  540. Thσá functioεá sound(⌐ anΣ sounds(⌐ allo≈ thσ prograφ t∩á producσ ì
  541. sound≤ othe≥ thaε thosσ oε thσ norma∞ musica∞ scale«  Thσ penalt∙ ì
  542. fo≥á thi≤ flexibilit∙ i≤ tha⌠ morσ worδ i≤ usuall∙á requireΣá  t∩ ì
  543. specif∙ thσ frequenc∙ anΣ duratioε oµ eacΦ sound¼ especiall∙ wheε ì
  544. forming complex noises.
  545.  
  546. T∩á producσ ß singlσ sound¼á cal∞á sound()«á  Simple¼á eh┐á  Jus⌠ ì
  547. providσá thσá frequenc∙á a≤á (H· ¬ 100)¼á anΣá thσá duratioεá iε ì
  548. milliseconds«á  T∩ producσ ß serie≤ oµ sounds¼á yo⌡ caε se⌠ u≡ aε ì
  549. arra∙á oµá structure≤á oµ thσ typσ sound_elemen⌠ anΣ pas≤á i⌠á t∩ ì
  550. sounds()¼á alonτá witΦ ß coun⌠ oµ thσ numbe≥ oµá elements«á  EacΦ ì
  551. elemen⌠á take≤ u≡ si° bytes╗á fou≥ byte≤ fo≥ thσ frequenc∙á (lonτ ì
  552. int⌐ anΣ tw∩ fo≥ thσ duratioε (unsigned).
  553.  
  554. .paè.he SounΣ Effect≤                               Functioε Descriptions
  555.  
  556.                       Summary Function List
  557.  
  558. Thesσá function≤á arσ describeΣ iε detai∞ later¼á bu⌠ herσá i≤á ß ì
  559. comprehensivσ lis⌠ oµ thσ function≤ iε thσ library¼ witΦ thσ filσ ì
  560. locatioε anΣ ß shor⌠ descriptioε oµ eacΦ one.
  561.  
  562.  
  563.                            High-Level
  564.  
  565. sound_init   SOUNDCTL    Call to set mode, etc.
  566. sound_done   SOUNDCTL    Call before exit.
  567. sound_modeáááSOUNDCTLáá  Returns current mode.
  568. sound     áááSOUNDáá     Make a noise.
  569. sounds    áááSOUNDáá     Make several noises.
  570. pla∙         PLAY        Makσ pleasan⌠ noise≤ usinτ eas∙ notation.
  571. quiet     áááSOUNDOUTáá  Kill playing background music.
  572. sound_bchk   SOUNDOUT    Check status of sound buffer.
  573.  
  574.                             Low-Level
  575.           
  576. spkr_on   áááSPKRCTLáá   Speaker on  (continuous noise) 
  577. spkr_off  áááSPKRCTLáá   Speaker off (blissful quiet)
  578. spkr_freq áááSPKRCTLáá   Sets the frequency of the noise
  579. spkr_cnt≥    SPKRCTL     Set≤ frequenc∙ als∩ (seσ funπ description)
  580.           
  581.                      Internal --- DO NOT USE
  582.           
  583. sound_out    SOUNDOUT    Interrupt-driven output routine
  584. snd_irh      SOUNDINT    Assembly interface for sound_out
  585. snd_brk      SOUNDINT    Built-in break handler
  586. snd_giv      SOUNDINT    Utility - get interrupt vector
  587. snd_siv      SOUNDINT    Utility - set interrupt vector
  588. delay        DELAY       Internal delay loop used in mode 1               
  589. .paè                      SOUND_INIT and SOUND_DONE
  590.  
  591. Purpose:
  592.  
  593. áááááSe⌠ u≡ anΣ tea≥ dowε thσ interrup⌠ vector≤ needeΣ t∩ providσ ì
  594. ááááásound.
  595.  
  596. Summary:
  597.  
  598.      int sound_init(mode,install_bh)
  599. áááááint mode, install_bh;
  600.  
  601. áááááint sound_done();
  602.  
  603. Parameters:
  604.  
  605. áááááMode:     áááááMus⌠ bσ iε thσ rangσ 1..5╗  set≤ thσ modσ fo≥ ì
  606. áááááááááááááááááááásubsequen⌠áá call≤á t∩á sound(⌐á anΣá play()«  ì
  607. ááááááááááááááááááááValues are:
  608.  
  609.                      1  Foreground w/ Delay Loop               
  610.                      2  Foreground w/ Standard Clock Interrupt 
  611.                      3  Foreground w/ Enhanced Clock Interrupt
  612.                      4  Background w/ Standard Clock Interrupt 
  613.                      5  Background w/ Enhanced Clock Interrupt
  614.  
  615. áááááInstall_bh:á   Iµá thi≤á i≤á 0¼á n∩á break-handle≥á wil∞á bσ ì
  616. ááááááááááááááááááááinstalled«á  Otherwise¼á ß breaδ handle≥ wil∞ ì
  617. áááááááááááááááááááábσ installed«á  Seσ Technica∞ Informatioε fo≥ ì
  618. ááááááááááááááááááááß completσ descriptioε oµ thσ breaδ handler.
  619.  
  620. Returns:
  621.  
  622.      Zer∩á indicate≤ success«á  Sound_ini⌠ wil∞ returε -▒á iµá aε ì
  623. áááááinvaliΣ modσ i≤ passed.
  624.  
  625. Notes:
  626.  
  627. áááááSound_init(⌐á ma∙á bσ calleΣ morσ thaε oncσ withou⌠á harmfu∞ ì
  628. áááááeffects«á  Wheε called¼á an∙ musiπ currentl∙ playinτ wil∞ bσ ì
  629. ááááákilled«á  Yo⌡ caε usσ call≤ t∩ sound_init(⌐ t∩ changσá mode≤ ì
  630. ááááádurinτ thσ application.
  631.  
  632. áááááSound_done(⌐ shus⌠ ofµ backgrounΣ musiπ anΣ thσ speaker¼ anΣ ì
  633. áááááclean≤á u≡ an∙ interrup⌠ vector≤ whicΦ ma∙ havσ beeε changeΣ ì
  634. áááááb∙ sound_init()«  Thi≤ let≤ thσ applicatioε safel∙ exit.
  635.  
  636. .paè                           SOUND_MODE
  637.  
  638. Purpose:
  639.  
  640. áááááReturn≤á thσ curren⌠ sounΣ mode«á  Seσ sound_init(⌐ fo≥á thσ ì
  641. ááááápossible values.
  642.  
  643. Summary:
  644.  
  645.      int sound_mode()
  646.  
  647. Parameters:
  648.  
  649. áááááNone
  650.  
  651. Returns:
  652.  
  653.      Return≤áá curren⌠á mode¼áá rangσá 1-5«áá  Seσáá sound_init(⌐ ì
  654. ááááádescription for complete list of modes.
  655.  
  656. .paè                        SOUND  &  SOUNDS
  657.  
  658. Purpose:
  659.  
  660.      Producσ ß sounΣ o≥ sound≤ fo≥ ß certaiε time.
  661.  
  662. Summary:
  663.  
  664.      void sound(freq,dur)
  665.      long freq;
  666.      unsigned dur;
  667.  
  668. ááááávoid sounds(n,sa)
  669. áááááint n;
  670. ááááástruct sound_desc *sa;ááááá
  671.  
  672. Parameters:
  673.  
  674.      freq:  Frequenc∙ iε MH· ¬ 10«á  Ex║ 400MH· passeΣ a≤ 40000L«  ì
  675. ááááááááááááThσá allowablσá rangσ i≤ ???«á  ┴ frequenc∙ oµá ░á i≤ ì
  676. áááááááááááátreateΣá a≤ "silence"«á  ┴ sounΣ witΦ ß duratioε oµ ░ ì
  677. ááááááááááááis ignored.
  678.  
  679.      dur:   Duration of sound in milliseconds.
  680.  
  681. ááááán:     Numbe≥ oµ sound≤ passed«á  Number≤ les≤ thaε zer∩ arσ ì
  682. áááááááááááátreated as zero.
  683.  
  684. ááááása:á   Arra∙á oµá sounΣá descriptions¼áá eacΦá containinτá ß ì
  685. ááááááááááááfrequenc∙á anΣ ß duration¼á a≤ pe≥ thσ fre±á anΣá du≥ ì
  686. ááááááááááááparameter≤ passeΣ t∩ sound.
  687.  
  688. Returns:
  689.  
  690.      0 if all parameters all OK
  691.     -1 if error in parameters (out of range).     
  692.  
  693. Error Handling:
  694.  
  695.      Checks parameter range only.
  696.  
  697. Notes:
  698.  
  699. áááááThesσá function≤á arσ effecteΣ b∙ thσ modσ currentl∙ se⌠á b∙ ì
  700. áááááthσá mos⌠ recen⌠ cal∞ t∩ sound_init«á  The∙ ma∙ bσ useΣá fo≥ ì
  701. áááááeither foreground or background operation.
  702.  
  703. .paè                              PLAY
  704.  
  705. Purpose:
  706.  
  707.      Pla∙ ß serie≤ oµ musica∞ note≤ usinτ aε eas∙ notation.
  708.  
  709. Summary:
  710.  
  711.      void play(music)
  712.      char *music;
  713.  
  714. Parameters:
  715.  
  716. áááááThσá musiπá paramete≥á i≤ ß strinτ whicΦá caεá contaiεá man∙ ì
  717. ááááácomple°á operations¼á al∞á oµá whicΦ arσá describeΣá iεá thσ ì
  718. ááááásection "Making Music".
  719.  
  720. Returns:
  721.  
  722.      Nothing.
  723.  
  724. Error Handling:
  725.  
  726. áááááAn∙á problem≤ encountereΣ iε thσ musiπ strinτ arσ handleΣ a≤ ì
  727. ááááádescribeΣ iε thσ section "Making Music."
  728.  
  729. Notes:
  730.  
  731.      Thσá pla∙ functioε introduce≤ aε amoun⌠ oµ overheaΣ iε term≤ ì
  732. áááááoµ codσ size¼á a≤ i⌠ mus⌠ parsσ thσ string«  ┴ prograφ whicΦ ì
  733. ááááái≤á memory-critica∞á shoulΣ usσá sounds()╗á  oµá coursσá thσ ì
  734. áááááprogramme≥á mus⌠á theε perforφ thσ tasδ oµá convertinτá eacΦ ì
  735. ááááánotσ int∩ onσ o≥ morσ sounds« 
  736.  
  737. áááááSee "Making Music" for details on play()'s operation.
  738. ì
  739. .paè                DIRECT SPEAKER CONTROL FUNCTIONS
  740.  
  741. Purpose:
  742.  
  743.      Direct control of speaker port.
  744.  
  745. Summary:
  746.  
  747.      void spkr_on()
  748.  
  749. ááááávoid spkr_off()
  750.  
  751. ááááávoid spkr_freq(f)
  752. ááááálong f;
  753.  
  754. ááááávoid spkr_cntr(c)
  755. áááááunsigned c;
  756.  
  757. Parameters:
  758.  
  759. áááááThσá paramete≥á t∩ spkr_fre± i≤ thσ frequenc∙ iε MH· t∩á se⌠ ì
  760. áááááthσá speake≥ to«á  Thσ paramete≥ t∩ spkr_cnt≥ i≤ thσá actua∞ ì
  761. ááááácounte≥á valuσ t∩ bσ passeΣ t∩ thσ 825│á time≥á chip«á  Notσ ì
  762. ááááátha⌠á thσ onl∙ function≤ t∩ actuall∙ turε thσ speake≥ oεá o≥ ì
  763. áááááofµá arσ spkr_oε anΣ spkr_off╗á  settinτ thσ frequenc∙á doe≤ ì
  764. ááááánot imply activating or deactivating the speaker.ì
  765.  
  766. Returns:
  767.  
  768. áááááNothing.
  769.  
  770. Error Handling:
  771.  
  772.      None.  
  773.  
  774. Notes:
  775.  
  776.      Unlikσ sound()¼á sounds()¼á anΣ play()¼á whicΦ caε bσ freel∙ ì
  777. áááááintermixed¼á usσá oµá thesσá low-leve∞á function≤á whilσá iε ì
  778. ááááábackgrounΣá modσá caε disrup⌠ thσ backgrounΣá music«á  Whilσ ì
  779. áááááthi≤á i≤ fa≥ froφ fatal¼á i≤ caε producσ unpleasan⌠á noises«  ì
  780. áááááCal∞ quiet(⌐ beforσ usinτ thesσ functions.
  781.  
  782. .paè
  783.                    BACKGROUND-BUFFER FUNCTIONS
  784.  
  785. Purpose:
  786.  
  787.      Control music playing in background.
  788.  
  789. Summary:
  790.  
  791.      void quiet()
  792.  
  793. ááááávoid sound_bchk(used,avail)
  794. áááááint *used, *avail;
  795.  
  796. Parameters:         
  797.  
  798. áááááquite:              none.
  799.  
  800. ááááásound_buffchk():    used to return values (see below).
  801.  
  802. Returns:            
  803.  
  804. áááááquiet() has no return value.
  805.  
  806. ááááábuffchk(⌐ return≤ thσ numbe≥ oµ sounΣ element≤ iε thσ buffe≥ ì
  807. áááááanΣ thσ numbe≥ oµ freσ elements¼á viß thσ parameter≤á "usedó ì
  808. áááááanΣ "availó respectively.
  809.  
  810. Error Handling:     
  811.  
  812. áááááNone.
  813.  
  814. Notes:
  815.  
  816.      ┴á cal∞ t∩ quie⌠ wil∞ kil∞ an∙ backgrounΣ music¼á flusΦá thσ ì
  817. ááááábuffer¼ anΣ shu⌠ ofµ thσ speaker«  
  818.  
  819. .paè.he Sound Effects                               Technical Information
  820.  
  821.                      =======================
  822.                       TECHNICAL INFORMATION
  823.                      =======================
  824.  
  825. ╔á havσ trieΣ t∩ bσ clea≥ anΣ precisσ iε thesσá technica∞á notes«  ì
  826. ShoulΣá yo⌡á finΣ an∙ error≤ iε codσ o≥á documentation¼á o≥á havσ ì
  827. suggestion≤ fo≥ improvement¼á  ╔ woulΣ appreciatσ you≥á feedback«  ì
  828. Thesσá paragraph≤á arσá no⌠ fo≥ thσ fain⌠á oµá heart«á  Fo≥á morσ ì
  829. details¼á ╔á sugges⌠ somσ oµ Pete≥ Norton'≤  excellen⌠ P├á books¼ ì
  830. anΣ thσ ever-cryptiπ bu⌠ fact-filleΣ IB═ Technica∞ Reference.
  831.  
  832. Here is a brief summary of this section:
  833.  
  834.  
  835.      Timing Sound Duration (MODES)
  836.         Delay Loop - How, Pro & Con
  837.         Timer Interrupt - How, Pro & Con
  838.         Enhanced Interrupt - How, Pro & Con
  839.  
  840.      Sound Generation Mechanics
  841.         Speaker Logic
  842.         Setting The Frequency
  843.  
  844.      The Background Buffer
  845.  
  846.      The Break Handler
  847.  
  848.      The Interrupt Handler
  849.  
  850.           
  851.                     =========================
  852.                     TIMING THE SOUND DURATION
  853.                     =========================
  854.  
  855. Therσá arσ fivσ mode≤ iε whicΦ thσ sounΣ routine≤ caε run«á  The∙ ì
  856. definσá WHE╬á thσ musiπ plays¼á anΣ ho≈ thσá prope≥á DURATIO╬á i≤ ì
  857. determined«  Thσ FREQUENC┘ oµ thσ sound≤ i≤ alway≤ determineΣ anΣ ì
  858. produceΣ b∙ thσ samσ methoΣ regardles≤ oµ mode¼á anΣ i≤ describeΣ ì
  859. ß fe≈ paragraph≤ below.
  860.  
  861.   Mode   When          Timing
  862.   ----   ----          ------
  863.     1    Foreground    Delay Loop
  864.     2    Foreground    Standard Clock Interrupt
  865.     3    Foreground    Enhanced Clock Interrupt
  866.     4    Background    Standard Clock Interrupt
  867.     5    Background    Enhanced Clock Interrupt
  868.  
  869. Thσá defaul⌠ modσ i≤ modσ 1«á  I⌠ pose≤ thσ fewes⌠ problems¼á bu⌠ ì
  870. ha≤ somσ limitations«  Thσ timinτ i≤ achieveΣ usinτ ß dela∙ loop¼ ì
  871. whicΦá i≤á simpl∙á ß smal∞ piecσ oµ codσ witΦ ßá knowεá executioε ì
  872. time«á  B∙ loopinτ througΦ thi≤ piecσ oµ codσ yo⌡ caε approximatσ ì
  873. thσ duratioε oµ thσ sound≤ fairl∙ well«á  
  874. èUnfortunately¼á thσá dela∙ loo≡ methoΣ ha≤ problems«á  I⌠ i≤ ver∙ ì
  875. dependen⌠ oε thσ hardware, for one thing«á  ┴ processo≥á runninτ ì
  876. a⌠á 8MH·á wil∞á executσ thσ codσ iε closσ t∩ halµ thσ timσá oµá ß ì
  877. standarΣá P├ runninτ a⌠ 4.77MHz¼á s∩ thσ sound≤ wil∞ bσá shorter«  ì
  878. Also¼ thσ timinτ become≤ dependen⌠ oε processo≥ type«  Thσ norma∞ ì
  879. PC has an 8088;  oε aεá AT&╘ 6300  (8086) o≥ oε a PC-A╘ (80286),ì
  880. therσá wil∞ bσ ß noticeablσ timinτ differencσ duσ t∩ thσá varyinτ ì
  881. bu≤ width≤ anΣ executioε speeds¼ eveε iµ thσ basσ processo≥ clocδ ì
  882. speeΣ wa≤ thσ same«á  AnΣ a≤ thσ coup-de-grace¼á thi≤ methoΣ wil∞ ì
  883. bσ throwε ofµ b∙ thσ occurancσ oµ interrupts«á  Aε interrup⌠ wil∞ ì
  884. causσá othe≥ codσ t∩ bσ executeΣ whicΦ wil∞ extenΣ thσá executioε ì
  885. timσ oµ thσ loop.
  886.  
  887. Fortunatel∙ therσ i≤ ß bette≥ timinτ methoΣ available«á  Therσ i≤ ì
  888. aεá on-boarΣ maiε systeφ clocδ chi≡ whicΦ provide≤ ß pulsσ witΦ ß ì
  889. frequenc∙á oµ abou⌠ 1.19MHz«á  Thi≤ i≤ steppeΣ dowε t∩á ßá morσ ì
  890. reasonablσ ratσ b∙ thσ 825│ counte≥ chip«á  Thσ mos⌠ familia≥ usσ ì
  891. oµá thi≤ i≤ t∩ providσ thσ systeφ tick¼á whicΦ occur≤ 18.▓ timσ ß ì
  892. seconΣ anΣ generate≤ thσ hardwarσ clocδ interrup⌠ (IRQ0¼á IN╘ 8)«  ì
  893. Thi≤á i≤á generall∙á independen⌠á oµá thσá clocδá speeΣá oµáá thσ ì
  894. processor¼á anΣ s∩ i≤ ß gooΣ timinτ sourcσ acros≤ thσ extendeΣ P├ ì
  895. family.
  896.  
  897. Wσ caε usσ thi≤ systeφ ticδ t∩ timσ thσ sounds«á  BotΦ foregrounΣ ì
  898. anΣá backgrounΣ method≤ caε d∩ this╗á  thσ foregrounΣ mode≤á wil∞ ì
  899. merel∙á wai⌠á arounΣá unti∞ thσ sounΣá i≤á over«á  Thereforσá thσ ì
  900. followinτá discussion≤á oµ thσ usσ oµ thσ systeφá ticδá interrup⌠ ì
  901. appl∙ t∩ botΦ foregrounΣ anΣ background.
  902.  
  903. Thσá standarΣá interrup⌠ mode≤ (▓ anΣ 4⌐ tiσá int∩á thσá softwarσ ì
  904. interrup⌠á vecto≥á 0x1C«á  Thi≤á i≤ thσá "use≥á time≥á interruptó ì
  905. vector¼ anΣ i≤ provideΣ b∙ thσ BIO╙ a≤ ß nicσ wa∙ t∩ tiσ softwarσ ì
  906. int∩áá thσá timer«áá  Thσá BIO╙á interrup⌠á handle≥á retain≤á al∞ ì
  907. responsibilit∙á fo≥ handlinτ thσ mess∙ task≤ oµá sendinτá end-of-ì
  908. interrup⌠á t∩á thσ interrup⌠ controlle≥á chip¼á incrementinτá thσ ì
  909. time-of-da∙á clocδ tick¼á etc«á  Thi≤ i≤ ß cleaε wa∙ t∩á usσá thσ ì
  910. system tick to time events.
  911.  
  912.                         Possible Problems
  913.  
  914. Therσá arσá onl∙ tw∩ possiblσ problem≤ (tha⌠ ╔ caε see⌐ t∩á usinτ ì
  915. thσá systeφá tick«á  Onσá i≤ tha⌠ somσá memory-residen⌠á softwarσ ì
  916. package≤á arσ ver∙ possessivσ abou⌠ interrupts«á  Tha⌠ i≤ wh∙á s∩ ì
  917. man∙ oµ theφ arσ incompatiblσ witΦ eacΦ other«á  Iεá theory¼á an∙ ì
  918. numbe≥á oµá driver≤ coulΣ sharσ thσ use≥ systeφ ticδ b∙á chaininτ ì
  919. themselve≤ together¼á bu⌠ the∙ ofteε don't«á  Thi≤ softwarσ does¼ ì
  920. s∩ i⌠ wil∞ worδ witΦ well-behaveΣ utilities.
  921.  
  922. Thσ othe≥ probleφ mainl∙ involve≤ backgrounΣ mode«á  Iµ thσá use≥ ì
  923. abort≤ thσ prograφ b∙ usinτ contro∞ Ctrl-Break¼ interrup⌠ vector≤ ì
  924. wil∞á no⌠ bσ restored¼á anΣ eventuall∙ thσ systeφ wil∞ crasΦá anΣ ì
  925. neeΣá rebooting«á  Thi≤á caε bσ preventeΣ b∙ usinτá thσá provideΣ ì
  926. breaδ handle≥ (seσ SOUND_INIT⌐ o≥ b∙ callinτ sound_done(⌐ iµ you≥ ì
  927. applicatioε alread∙ provide≤ it≤ owε breaδ handler.
  928. è                         Enhanced Modes 
  929.  
  930. Thσá enhanceΣá interrup⌠á mode≤á (│ anΣá 5⌐á arσá no⌠á ye⌠á full∙ ì
  931. implemented¼á anΣá arσá presentl∙á thσá samσ a≤á mode≤á ▓á anΣá ┤ ì
  932. respectively«á  Iε ß futurσ release¼ the∙ wil∞ follo≈ thσ examplσ ì
  933. oµá BASI├ anΣ changσ thσ systeφ ticδ generatioε t∩ providσ bette≥ ì
  934. resolution«á  Thi≤ ticδ i≤ speΣ u≡ b∙ ß facto≥ oµ 4«á  Thσá sounΣ ì
  935. systeφá mus⌠ intercep⌠ thi≤ ticδ a⌠ thσ IN╘ ╕ level¼á anΣ providσ ì
  936. thσ ticδ t∩ thσ BIO╙ onl∙ ever∙ fourtΦ time¼á t∩ kee≡ thσá systeφ ì
  937. time-of-da∙á clocδ froφ speedinτ ahead«á  Thσ advantagσ i≤ bette≥ ì
  938. timσ resolution.
  939.  
  940. Thσá disadvantage≤ t∩ thσ enhanceΣ mode≤ includσ al∞ oµ thσá one≤ ì
  941. giveε fo≥ thσ standarΣ clocδ modes¼ plu≤ thσ codσ ha≤ t∩ diτ eveε ì
  942. deepe≥á int∩á territor∙á wherσá application≤á program≤á arσáá no⌠ ì
  943. encourageΣá t∩á venture«á  Still¼á takinτ prope≥ carσ t∩á restorσ ì
  944. vector≤ upoε exit¼á thi≤ shoulΣ bσ cleaε enougΦ fo≥ everyda∙ use«  ì
  945. Therσ i≤ ß questioε a≤ t∩ thσ valuσ oµ thσ morσ precisσ timinτ oµ ì
  946. thσ sounds¼ whicΦ ma∙ no⌠ bσ oµ grea⌠ importancσ anyway.
  947.  
  948.  
  949.                    ==========================
  950.                    SOUND GENERATION MECHANICS
  951.                    ==========================
  952.  
  953.                           Speaker Logic
  954.  
  955. Thσá sound≤á arσ produceΣ usinτ thσ speake≥ attacheΣ t∩á thσá IB═ ì
  956. motherboard«á  Thσá speake≥á i≤ pulseΣ t∩ providσá sounΣá oµá thσ ì
  957. desireΣá frequency«á  Thσ pulsinτ actioε i≤ provideΣ courtes∙á oµ ì
  958. thσáá maiεáá systeφá clock¼áá steppeΣá dowεá througΦáá thσáá 825│ ì
  959. programmablσ counter«  Therσ i≤ als∩ aε on/ofµ switcΦ provideΣ b∙ ì
  960. ßá bi⌠á iεá thσá PP╔ chip«á  Thσá speake≥á contro∞á circuitr∙á i≤ ì
  961. logicall∙ (no⌠ electrically⌐ diagrammeΣ as:
  962.  
  963.     +-------+    +--------+
  964.     | 8284A |--->| 8253-5 |----+                      
  965.     +-------+    +--------+    |    ____               /|
  966.                                +--> )   \             / |
  967.                                     |AND >---------->[  |
  968.                                +--> )___/             \ |
  969.               +-----+          |                       \|
  970.               | PPI |----------+                    
  971.               +-----+                                Speaker
  972.  
  973. Thσá PP╔ switcΦ i≤ accesseΣ a≤ bit≤ ░ anΣ ▒ a⌠ I/╧ addres≤á 0x61«  ì
  974. Wheε thσ bit≤ arσ se⌠ thσ speake≥ switcΦ i≤ on¼á wheε cleareΣ thσ ì
  975. speake≥á switcΦá i≤á off«áá  Seσá thσá spkr_on(⌐á anΣá spkr_off(⌐ ì
  976. function≤ t∩ seσ ho≈ t∩ d∩ thi≤ froφ C«á  Notσ tha⌠ thσ valuσá oµ ì
  977. thσá PP╔á i≤á firs⌠ read¼á thσ requireΣ bit≤á changed¼á anΣá theε ì
  978. writteεá out«á  Thi≤ i≤ necessar∙ becausσ thσ PP╔ ha≤ man∙á othe≥ ì
  979. use≤ fo≥ thσ res⌠ oµ thσ bits.
  980.  
  981. .cp 6è                Setting Frequency using the 8253
  982.  
  983. Thσáá systeφá clocδá oscillate≤á a⌠á abou⌠á 1.19MHz«áá  Thσá 825│ ì
  984. programmablσ counte≥ step≤ dowε thi≤ frequenc∙ b∙ sendinτ ß pulsσ ì
  985. fo≥á ever∙ s∩ man∙ inpu⌠ pulses«á  Thσ well-knowε systeφ ticδá oµ ì
  986. 18.▓á tick≤ pe≥ seconΣ i≤ obtaineΣ usinτ thi≤ chi≡ anΣ ßá diviso≥ ì
  987. oµ 0xFFFF«  Thσ chi≡ ha≤ tw∩ counters╗  whilσ onσ outpu⌠ connect≤ ì
  988. t∩á thσ systeφ clocδ interrupt¼á thσ othe≥ tie≤ t∩á thσá speaker«  ì
  989. So¼á b∙á changinτ thσ diviso≥ iε thσ counter¼á wσ caε changσá thσ ì
  990. frequenc∙á oµá thσá pulse≤á sen⌠ t∩ thσá speake≥á anΣá hencσá thσ ì
  991. frequenc∙ oµ thσ sounΣ i⌠ produces.
  992.  
  993. Fo≥á morσá detail≤ oε thσ usσ oµ thσ 825│á programmablσá counter¼ ì
  994. consult the Intel part spec.  
  995.  
  996.  
  997.                       =====================
  998.                       THE BACKGROUND BUFFER
  999.                       =====================
  1000.  
  1001. Sound≤á t∩ bσ playeΣ iε mode≤ ▓ througΦ ╡ arσ placeΣ iε ßá buffe≥ ì
  1002. anΣá playeΣá unde≥ interrup⌠ control«á  Sincσ thi≤ buffe≥á i≤á oµ ì
  1003. finitσ size¼ i⌠ i≤ possiblσ t∩ overflow«  Overflowinτ sound≤ wil∞ ì
  1004. bσ discarded.
  1005.  
  1006. EacΦ entr∙ take≤ u≡ fou≥ (4⌐ bytes¼á anΣ thσ numbe≥ oµ entrie≤ iε ì
  1007. thσá buffe≥á i≤ fixeΣ wheε yo⌡ builΣ thσ library«á  Thσá compileΣ ì
  1008. file≤ oε thσ disδ havσ ß defaul⌠ buffe≥ sizσ oµ 6┤ entries«á  Yo⌡ ì
  1009. caεáá changσá thi≤á b∙á changinτá thσá valuσá oµáá thσáá constan⌠ ì
  1010. SND_BUFFSIZ┼ iε SOUND.╚ anΣ recompilinτ thσ system.
  1011.  
  1012. EacΦá notσ sen⌠ t∩ play(⌐ wil∞ usuall∙ generatσ tw∩ entries¼á onσ ì
  1013. fo≥ thσ notσ anΣ onσ fo≥ thσ inter-notσ pause«  Usinτ sound(⌐ anΣ ì
  1014. sounds(⌐ wil∞ generatσ exactl∙ onσ entr∙ pe≥ sounΣ element.
  1015.  
  1016. Thσá sounΣ buffe≥ i≤ circular¼á s∩ tha⌠ a≤ entrie≤ arσ outpu⌠á t∩ ì
  1017. thσ speaker¼á morσ caε bσ added«á  Checδ thσ statu≤ oµ thσ buffe≥ ì
  1018. usinτ thσ functioε sound_bchk()¼á whicΦ wil∞ ge⌠ yo⌡ botΦá thσ ì
  1019. numbe≥ oµ entrie≤ useΣ anΣ thσ numbe≥ oµ entrie≤ free.
  1020.  
  1021.  
  1022.                        ===================
  1023.                         THE BREAK HANDLER
  1024.                        ===================
  1025.  
  1026. Thσá built-iεá breaδ handle≥ ha≤ ß simplistiπ vie≈ oµá life«á  I⌠ ì
  1027. accept≤á control¼á call≤ sound_done(⌐ t∩ cleaεá up¼á theεá passe≤ ì
  1028. contro∞á t∩ thσ breaδ handle≥ tha⌠ precede≤ it«á  Thi≤ mean≤ tha⌠ ì
  1029. thσ usua∞ ne⌠ resul⌠ i≤ aε exi⌠ t∩ DOS¼ bu⌠ safely«  Fee∞ freσ t∩ ì
  1030. usσá thσá giveε functioε a≤ ß template¼á bu⌠á kee≡á thσá origina∞ ì
  1031. arounΣ iε casσ yo⌡ accidentall∙ mucδ i⌠ u≡ ß bit.
  1032.  
  1033. .cp 15è                     =======================
  1034.                       THE INTERRUPT HANDLER
  1035.                      =======================
  1036.  
  1037. Thi≤á refer≤á  t∩á thσ time≥ interrup⌠á handler¼á ßá ver∙á simplσ ì
  1038. routine«á  It≤á joΓ i≤ t∩ savσ thσ registers¼á loaΣá thσá segmen⌠ ì
  1039. register≤ tha⌠ ├ function≤ expect¼ cal∞ sound_out(⌐ t∩ d∩ al∞ thσ ì
  1040. work¼á anΣ restorσ al∞ thσ registers«á  I⌠ theε call≤ thσ routinσ ì
  1041. whicΦá wa≤á previousl∙á thσ interrup⌠ handler«á  Thi≤ i≤á ßá nicσ ì
  1042. courteou≤á thinτá t∩ do¼á a≤ i⌠ allow≤ sharinτ oµá thi≤á valuablσ ì
  1043. resource¼ thσ systeφ tick.
  1044.  
  1045.  
  1046. .paè                      WHEN THINGS GO WRONG
  1047.  
  1048. Firs⌠ oµ all¼á pleasσ fee∞ freσ t∩ asδ mσ (thσ author⌐ questions«  ì
  1049. ╔ canno⌠ accep⌠ phonσ question≤ a⌠ thi≤ time¼ mainl∙ becausσ ╔ aφ ì
  1050. no⌠á nea≥ an∙ particula≥ phonσ durinτ thσ day«á  Yo⌡ caε reacΦ mσ ì
  1051. b∙ mai∞ o≥ b∙ CompuServσ EASYMAI╠ (73047,3715)«á  Bu⌠ first¼á seσ ì
  1052. iµ thσ followinτ lis⌠ ha≤ you≥ probleφ oε it.
  1053.  
  1054.  
  1055. "I cannot read the distribution disk."
  1056.  
  1057.      Thσá distributioεá disδ i≤ provideΣ iε IB═á double-sideΣá 9-ì
  1058. ááááásecto≥ format«  Yo⌡ wil∞ no⌠ bσ ablσ t∩ reaΣ i⌠ witΦ single-ì
  1059. ááááásideΣ drive≤ o≥ witΦ ß DO╙ versioε beforσ 2.0.
  1060.  
  1061. áááááIµ yo⌡ caε reaΣ sucΦ disk≤ normally¼á therσ i≤ ß chancσ tha⌠ ì
  1062. áááááthσ diskettσ ha≤ beeε damageΣ iε transit«  Pleasσ returε thσ ì
  1063. ááááádiskette and you will get another copy, no charge.
  1064.  
  1065.  
  1066. "The files will not compile on my system."
  1067.  
  1068. áááááIµá yo⌡ arσ usinτ ß non-supporteΣ compiler¼á al∞ ╔ caε d∩ i≤ ì
  1069. ááááárefe≥ yo⌡ t∩ thσ sectioε oε Settinτ U≡ fo≥ Othe≥ Compilers"«  ì
  1070. áááááIµá yo⌡á d∩á ge⌠á everythinτ working¼á eveεá iµá jus⌠á oεá ß ì
  1071. ááááádifferen⌠á versioεá oµá Latticσá o≥á Manx/Aztec¼áá ╔áá woulΣ ì
  1072. áááááappreciatσá iµ yo⌡ le⌠ mσ know«á  ╔ wil∞ d∩ everythinτ ╔ caε ì
  1073. ááááát∩ hel≡ yo⌡ ge⌠ i⌠ compileΣ anΣ running¼á bu⌠ withou⌠ ß cop∙ ì
  1074. áááááoµá thσá compile≥ (D╧ NO╘ SEN─ M┼á COPYRIGHTE─á SOFTWARE⌐á ╔ ì
  1075. ááááácannot promise much.
  1076.  
  1077. áááááBσá surσá yo⌡ havσ thσ filσ SOUND.╚ wherσ you≥ compile≥á caε ì
  1078. áááááfinΣá it«á  Als∩ bσ surσ tha⌠ yo⌡ havσ enougΦ rooφá oεá you≥ ì
  1079. ááááádiskettes for the compiler's output.
  1080.  
  1081. "My system locks up when I run a program using sound."
  1082.  
  1083. áááááFirst¼á iµ yo⌡ havσ an∙ memory-residen⌠ utilities¼ let'≤ ge⌠ ì
  1084. áááááriΣá oµ theφ fo≥ thσ moment«á  De-instal∞ them¼á eveε removσ ì
  1085. ááááátheφá froφ you≥ AUTOEXEC.BA╘ file¼á theε reboo⌠ thσá system«  ì
  1086. áááááTry the program again.  If it still crashes ...
  1087.  
  1088. áááááMake sure you are calling quiet() before the program exits.
  1089.  
  1090. .paè
  1091.  
  1092.                            ==========
  1093.                            CHANGE LOG
  1094.                            ==========
  1095.  
  1096. Version 1.0b  (OPEN)
  1097.  
  1098.         Added new file SOUNDP.H containing prototypes for all
  1099.         user-callable functions, for compilers which support
  1100.         prototyping.
  1101.  
  1102.         Added support for Ecosoft Eco-C88 compiler.
  1103.  
  1104.         Compressed definition of Install in SOUNDCTL, by combining
  1105.         all definitions using typedef's and #defines to allow for
  1106.         compiler and library differences.
  1107.  
  1108.  
  1109. Version 1.0a  (2/20/85)
  1110.  
  1111.         Delay now written in assembler.
  1112.  
  1113.         Corrected error in play(), which would not play dotted
  1114.         notes if a length was also specified.  
  1115.  
  1116.         Corrected error in SOUND.H's definition of MS2TICKS, which
  1117.         was miscalculated and rounding badly.
  1118.